package deltax.common.respackage
{
    import deltax.common.math.*;
    import deltax.common.respackage.common.*;
    import flash.utils.*;

    public class ResSettingItem extends Object
    {
        public var swfUrl:String;
        private var m_allSymbolObjects:Dictionary;
        private var m_swfRawDataLoadState:int = 0;
        private var m_refCount:uint;

        public function ResSettingItem()
        {
            return;
        }// end function

        public function analyzeXML(param1:XML, param2:Dictionary) : void
        {
            var _loc_3:XML = null;
            var _loc_4:String = null;
            var _loc_5:String = null;
            var _loc_6:String = null;
            this.swfUrl = param1.@url;
            this.m_refCount = 0;
            for each (_loc_3 in param1.file)
            {
                
                this.m_allSymbolObjects = this.m_allSymbolObjects || new Dictionary();
                _loc_4 = String(_loc_3.@path);
                _loc_5 = String(_loc_3.@path).substring((_loc_4.lastIndexOf("/") + 1), _loc_4.lastIndexOf("."));
                _loc_6 = _loc_4.substr((_loc_4.lastIndexOf(".") + 1));
                this.m_allSymbolObjects[_loc_5 + "_" + _loc_6] = 0;
                param2[_loc_4.toLowerCase()] = this;
            }
            return;
        }// end function

        public function makeEmptyState() : void
        {
            this.m_allSymbolObjects = this.m_allSymbolObjects || new Dictionary();
            return;
        }// end function

        public function makeLoading() : void
        {
            this.m_swfRawDataLoadState = LoaderCommon.LOADSTATE_LOADING;
            return;
        }// end function

        public function get swfRawDataLoadState() : uint
        {
            return this.m_swfRawDataLoadState;
        }// end function

        public function get versionedSwfUrl() : String
        {
            return this.swfUrl;
        }// end function

        public function reference() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this.m_refCount + 1;
            _loc_1.m_refCount = _loc_2;
            return;
        }// end function

        public function release() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this.m_refCount - 1;
            _loc_1.m_refCount = _loc_2;
            return;
        }// end function

        public function clearAllInnerFileLoadState() : void
        {
            var _loc_1:* = undefined;
            if (this.m_refCount != 0)
            {
                return;
            }
            for (_loc_1 in this.m_allSymbolObjects)
            {
                
                this.m_allSymbolObjects[_loc_1] = 0;
            }
            this.m_swfRawDataLoadState = LoaderCommon.LOADSTATE_NOLOAD;
            return;
        }// end function

        public function unpackAllFiles(param1:ByteArray) : void
        {
            var _loc_4:ByteArray = null;
            var _loc_5:String = null;
            var _loc_6:uint = 0;
            var _loc_7:uint = 0;
            var _loc_8:uint = 0;
            var _loc_9:uint = 0;
            var _loc_10:uint = 0;
            if (param1 == null)
            {
                this.m_swfRawDataLoadState = LoaderCommon.LOADSTATE_LOADFAILED;
                return;
            }
            var _loc_2:* = new ByteArray();
            _loc_2.writeBytes(param1, 8, param1.length - 8);
            _loc_2.uncompress();
            _loc_2.endian = Endian.LITTLE_ENDIAN;
            var _loc_3:* = _loc_2[0] >> 3;
            _loc_2.position = MathUtl.aligenUp(5 + 4 * _loc_3, 8) / 8 + 4;
            while (_loc_2.bytesAvailable)
            {
                
                _loc_6 = _loc_2.readUnsignedShort();
                _loc_7 = _loc_6 >>> 6;
                _loc_8 = (_loc_6 & 63) == 63 ? (_loc_2.readUnsignedInt()) : (_loc_6 & 63);
                _loc_9 = _loc_2.position + _loc_8;
                if (_loc_7 == 87)
                {
                    _loc_4 = new PackFileByteArray();
                    _loc_10 = _loc_2.readUnsignedShort();
                    _loc_4.writeBytes(_loc_2, _loc_2.position + 4, _loc_8 - 6);
                    if (this.m_allSymbolObjects[_loc_10] != null)
                    {
                        this.m_allSymbolObjects[this.m_allSymbolObjects[_loc_10]] = _loc_4;
                        delete this.m_allSymbolObjects[_loc_10];
                    }
                    else
                    {
                        this.m_allSymbolObjects[_loc_10] = _loc_4;
                    }
                }
                else if (_loc_7 == 76)
                {
                    _loc_2.position = _loc_2.position + 2;
                    _loc_10 = _loc_2.readUnsignedShort();
                    _loc_5 = _loc_2.readUTFBytes(_loc_8 - 5);
                    if (this.m_allSymbolObjects[_loc_10] != null)
                    {
                        this.m_allSymbolObjects[_loc_5] = this.m_allSymbolObjects[_loc_10];
                        delete this.m_allSymbolObjects[_loc_10];
                    }
                    else
                    {
                        this.m_allSymbolObjects[_loc_10] = _loc_4;
                    }
                }
                _loc_2.position = _loc_9;
            }
            this.m_swfRawDataLoadState = LoaderCommon.LOADSTATE_LOADED;
            return;
        }// end function

        public function getFileSize(param1:String) : uint
        {
            if (!this.m_allSymbolObjects)
            {
                return null;
            }
            var _loc_2:* = this.m_allSymbolObjects[param1] as PackFileByteArray;
            return _loc_2 ? (_loc_2.length) : (0);
        }// end function

        public function getFile(param1:String) : ByteArray
        {
            var _loc_3:ByteArray = null;
            if (!this.m_allSymbolObjects)
            {
                return null;
            }
            var _loc_2:* = this.m_allSymbolObjects[param1] as PackFileByteArray;
            if (!_loc_2)
            {
                return null;
            }
            if (_loc_2.m_innerFileLoadStatus == false)
            {
                _loc_2.m_innerFileLoadStatus = true;
                _loc_2.position = 0;
                return _loc_2;
            }
            _loc_3 = new ByteArray();
            _loc_3.writeBytes(_loc_2, 0, _loc_2.length);
            _loc_3.position = 0;
            return _loc_3;
        }// end function

    }
}

class PackFileByteArray extends ByteArray
{
    public var m_innerFileLoadStatus:Boolean;

    function PackFileByteArray()
    {
        return;
    }// end function

}

